function checkInt(dom,string){//var pattern = /^[\u4E00-\u9FA5]+$/i;
    var pattern = /[^\d]/g;
    if (checkNull(dom,string)){
        if (pattern.test(dom)){
            alert("请检查输入，"+string+"只能输入数字");
            return false;
        }
        return true;
    }
    return false;
}

function checkString(dom,string){
    var pattern = /^[\u4E00-\u9FA5]+$/i;
    if (checkNull(dom,string)) {
        if (!pattern.test(dom)) {
            alert("请检查输入，"+string+"只能输入中文");
            return false;
        }

        return true;
    }
    return false;
}

function checkNull(dom,string){
    if (dom.length==0||typeof dom =="undefined") {
        alert("请检查输入,"+string+"不能为空");
        return false;
    }else
    return true;
}




$(".add-cj").click(function(){
    var testName = $("#doc-vld-name-1-0").val().trim();
    var testNumber = $("#doc-vld-pwd-1-0").val().trim();
    var studentName = $("#doc-vld-name-2-0").val().trim();
    var studentNumber = $("#doc-vld-pwd-2-0").val().trim();
    var remark = $("#doc-vld-name-3-0").val().trim();
        if (checkInt(testNumber,"准考证号")&&checkInt(studentNumber,"学号")&&checkString(studentName,"姓名")&&checkNull(testName,"考试名")) {
            $.ajax({
                dataType: "json",
                url: "form/add.weixin",
                data: {
                    "testName": testName,
                    "testNumber": testNumber,
                    "remark": remark,
                    "studentName": studentName,
                    "studentNumber": studentNumber
                },
                type: "post",
                success: function (data) {
                    console.log(data);
                    if (data.data) {
                        $(".add").append("<ul class=\"add-2 toggle\"><i class=\"am-icon-file-text-o\"> </i>" + testName +
                            "&nbsp &nbsp   &nbsp<i class=\"am-icon-close  cj-delect\" id='" + data.id + "'  " +
                            "data-toggle=\"modal\" data-target=\".my-confirm\">删除&nbsp&nbsp </i>" +
                            " <i class=\"am-icon-clock-o  time\">2016年6月18日</i>  <i class=\"am-icon-sort-desc   flip\"> " +
                            " &nbsp   &nbsp</i> <li class=\"panel\">" +
                            " <i class=\"am-icon-at\">准考证号：" + testNumber +
                            "</i><br> <i class=\"am-icon-user\">姓 &nbsp  &nbsp &nbsp名：" + studentName +
                            "</i><br> <i class=\"am-icon-mortar-board\">" +
                            "学 &nbsp  &nbsp  &nbsp号：" + studentNumber + "</i> <br> <i class=\"am-icon-tag\">备 &nbsp  &nbsp  &nbsp注：" +
                            remark + "</i> </li></ul>");
                        $(".am-close").click();
                        $("#doc-vld-name-1-0").val("");
                       $("#doc-vld-pwd-1-0").val("");
                        $("#doc-vld-name-2-0").val("");
                         $("#doc-vld-pwd-2-0").val("");
                        $("#doc-vld-name-3-0").val("");
                    }
                    else
                        alert("请检查输入，同一考试准考证号无法重复");
                }
            });
        }

});

$(document).on('click','.cj-remove',function(){
  $(this).parent(".add-2").remove();
  });

$(document).ready(function(){
  $(document).on('click','ul.toggle',function(){
    $(this).children(".panel").slideToggle("slow");
  })
});


$(".add-1").click(function () {
    $(".time").fadeIn();
    $(".flip").fadeIn();
    $(".cj-delect").fadeOut();
    $("ul.add-2").addClass("toggle");
    $(".shou2").fadeOut();
    $(".shou1").fadeIn();
})

    $(document).ready(function(){
        $(".shou").click(function(){
            $(".shou").toggle();
            $(".time").toggle();
            $(".flip").toggle();
            $(".cj-delect").toggle();
            $("ul.add-2").toggleClass("toggle");
        });


        $("ol").on("click",".cj-delect", function () {
            var id = $(this).attr("id");
            $(".cj-remove").attr("id",id);
        })

        $(".cj-remove").click(function () {
            var id = $(this).attr("id");
            var data = {"id":id};
            $.ajax({
                type:"post",
                data:JSON.stringify(data),
                dataType:"json",
                contentType : "application/json",
                url:"form/delete.weixin",
                success: function (data) {
                    if (data)
                        $("#"+id).parent().remove();
                    else
                        alert("删除失败");
                }
            })
        });
    });





